//
//  TJClockInRecardCell.m
//  BaoDian
//
//  Created by mac on 2024/7/27.
//

#import "TJClockInRecardCell.h"
#import "TJUserPublishDataView.h"
#import "TJVideoCoverDownloader.h"

@interface TJClockInRecardCell()

@property (nonatomic, weak) TJTaskDouYinDataView *dataView;
@property (nonatomic, weak) UIImageView *coverImageView;
@property (nonatomic, weak) UILabel *nameLabel;
@property (nonatomic, weak) UILabel *addressLabel;
@property (nonatomic, weak) UILabel *videoLinkLabel;
@property (nonatomic, weak) UILabel *dateLabel;

@end

@implementation TJClockInRecardCell

- (void)settingSubView {
    [super settingSubView];
    
    self.backgroundColor = UIColor.tj_backgroundColor;
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    UIImageView *coverImageView = [UIImageView addToView:self.contentView];
    coverImageView.addCornerRadius(8);
    [coverImageView addTapGesturesWithTarget:self action:@selector(tapCoverImageView:)];
    [coverImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);
        make.left.offset(16);
        make.width.offset(116);
        make.height.offset(155);
    }];

    UIImageView *playerIconView = [UIImageView addToView:coverImageView];
    playerIconView.image = [UIImage imageNamed:@"videoPlayer_icon"];
    [playerIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.offset(0);
        make.width.height.offset(24);
    }];
    
    UILabel *nameLabel = [UILabel lableWithSuperView:self.contentView font:UIFontBoldMake(16) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentLeft];
    nameLabel.numberOfLines = 2;
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(coverImageView.mas_right).offset(10);
        make.top.equalTo(coverImageView);
        make.right.inset(16);
    }];
    
    UILabel *addressLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColor.whiteColor title:nil textAlignment:NSTextAlignmentLeft];
    addressLabel.backgroundColor = UIColorMake(0x2A2B31);
    addressLabel.addCornerRadius(4);
    [addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(coverImageView.mas_right).offset(10);
        make.top.equalTo(coverImageView).offset(50);
        make.right.mas_lessThanOrEqualTo(-16);
        make.height.offset(20);
    }];
    
    TJTaskDouYinDataView *dataView = [TJTaskDouYinDataView addToView:self.contentView];
    dataView.addCornerRadius(8);
    dataView.playerCountItem.textLabelTopMargin = 0;
    dataView.likeCountItem.textLabelTopMargin = 0;
    dataView.commentCountItem.textLabelTopMargin = 0;
    dataView.playerCountItem.textLabel.text = @"_";
    dataView.likeCountItem.textLabel.text = @"_";
    dataView.commentCountItem.textLabel.text = @"_";
    [dataView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nameLabel);
        make.right.inset(16);
        make.height.offset(34);
        make.top.equalTo(addressLabel.mas_bottom).offset(10);
    }];
    
    UILabel *videoLinkLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColorMake(0x8B94A2) title:nil textAlignment:NSTextAlignmentLeft];
    [videoLinkLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(dataView.mas_bottom).offset(8);
        make.left.right.equalTo(nameLabel);
    }];
    
    UILabel *dateLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(12) color:UIColorMake(0x8B94A2) title:nil textAlignment:NSTextAlignmentLeft];
    [dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(coverImageView);
        make.left.equalTo(nameLabel);
    }];
    
    _dataView = dataView;
    _coverImageView = coverImageView;
    _nameLabel = nameLabel;
    _addressLabel = addressLabel;
    _videoLinkLabel = videoLinkLabel;
    _dateLabel = dateLabel;
}

- (void)setModel:(TJClockInRecardModel *)model {
    _model = model;
    
    
    _nameLabel.text = model.text;
    _addressLabel.text = [NSString stringWithFormat:@"   %@   ", model.poiInfo];
    _videoLinkLabel.text = [NSString stringWithFormat:@"视频链接: %@", model.videoUrl];
    _dateLabel.text = [NSString stringWithFormat:@"发布时间: %@", model.createDate];
    _dataView.playerCountItem.textLabel.text = model.playCount;
    _dataView.likeCountItem.textLabel.text = model.diggCount;
    _dataView.commentCountItem.textLabel.text = model.commentCount;
    
    [[TJVideoCoverDownloader shareDownLoader] downloadWithUrl:model.videoUrl completion:^(UIImage * _Nullable thumbnail) {
        self.coverImageView.image = thumbnail;
    }];
}

- (void)tapCoverImageView:(UITapGestureRecognizer *)tap {
    UIImageView *imageView = (UIImageView *)tap.view;
    if (_tapCoverImageViewBlock) {
        _tapCoverImageViewBlock(imageView.image);
    }
}


@end
